/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.meego.common.queue;

import com.meego.common.log.GA;

/**
 *
 * @author TueHM
 */
public class QueueWorker implements Runnable {

    private Queue queue;
    private long _msleep_idle = 1000L;

    public QueueWorker(Queue queue) {
        this.queue = queue;
    }

    public void run() {
        while (true) {
            try {
                QueueCommand command = this.queue.take();
                if (command != null) {
                    command.execute();
                } else if (this._msleep_idle > 0L) {
                    Thread.sleep(this._msleep_idle);
                }

                continue;
            } catch (Exception ex) {
                GA.service.info("Error in exec QueueWorker", ex);
            }
        }
    }
}
